package com.epi.basic.expression;

import com.epi.domain.security.LoginUser;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author dxy
 * @version 1.0
 */
@Component("ex")
public class ExpressionRoot {
    public boolean hasAuthority(String authority) {
//        Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities();
//        GrantedAuthority grantedAuthority = authorities.stream().filter(a -> a.getAuthority().equals(authority)).findFirst().orElse(null);

        LoginUser loginUser = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<String> permissions = loginUser.getPermissions();
        permissions.add("1");
        return permissions.contains(authority);
    }
}
